<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>构造函数方法继承</title>
</head>
<body>
    <script>
        // 分开写
        // function Article(){
        //     this.url = "article/lists";
        //     this.get = function(param){
        //         let str = Object.keys(param)
        //         .map( value => `${value} = ${param[value]}`)
        //         .join('&');
        //         let url =`https://houdunren.com/${this.url}?${str}`;
        //         document.write(url+'<br>');
        //     };
        // };
        // let article1 = new Article();
        // article1.get({id:1,cat:'js'});

        // function User(){
        //     this.url = "user/lists";
        //     this.get = function(param){
        //         let str = Object.keys(param)
        //         .map( value => `${value} = ${param[value]}`)
        //         .join('&');
        //         let url =`https://houdunren.com/${this.url}?${str}`;
        //         document.write(url);
        //     };
        // }
        // let user1 = new User();
        // user1.get({id:1,user:'xiasnn'});


        // 整合后
        function Request(){
            this.get = function(param){
                let str = Object.keys(param)
                .map( value => `${value} = ${param[value]}`)
                .join('&');
                let url =`https://houdunren.com/${this.url}?${str}`;
                document.write(url+'<br>');
            };
        }

        function Article(){
            this.url = "article/lists";
            Request.apply(this);
        };
        let article1 = new Article();
        article1.get({id:1,cat:'js'});

        function User(){
            this.url = "user/lists";
            Request.call(this);
        }
        let user1 = new User();
        user1.get({id:1,user:'xiasnn'});
    </script>
</body>
</html>